package com.wcs.exam.common.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 难度等级(1:简单、2:一般、3:困难)
 */
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum DifficultyLevelEnum {

    /**
     * 简单
     */
    SIMPLE(1, "简单", ""),

    /**
     * 一般
     */
    GENERAL(2, "一般", ""),

    /**
     * 困难
     */
    DIFFICULT(3, "困难", "");

    /**
     * 编码
     */
    private final Integer code;

    /**
     * 描述
     */
    private final String desc;

    /**
     * 描述
     */
    private final String descEn;


    /**
     * 根据编码获取难度等级
     *
     * @param code 编码
     * @return 有效状态
     */
    public static DifficultyLevelEnum byCode(Integer code) {
        if (code == null) {
            return null;
        }
        for (DifficultyLevelEnum value : DifficultyLevelEnum.values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

    /**
     * 根据描述获取难度等级
     *
     * @param desc 描述
     * @return 难度等级
     */
    public static DifficultyLevelEnum byDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (DifficultyLevelEnum difficultyLevelEnum : DifficultyLevelEnum.values()) {
            if (difficultyLevelEnum.getDesc().equals(desc)) {
                return difficultyLevelEnum;
            }
        }
        return null;
    }

}
